<template>
  <div class="app-container">
    <div class="header">
      <div class="title">
        <i class="el-icon-data-board"></i><span>控制管理</span>
      </div>
      <div class="backB">
        <img src="@/assets/images/back.png" alt="" @click="goBack" />
      </div>
    </div>
    <div class="container">
      <div class="tob">
        <div>
          <div class="tobTitle">岛阀值设置</div>
          <el-table
            :data="tableDataTob"
            border
            :header-cell-style="{ background: '#1890ff', color: '#ffffff' }"
          >
            <el-table-column prop="isLand" label="岛类型">
              <template slot-scope="scope">
                <dict-tag
                  :options="dict.type.island_type"
                  :value="scope.row.isLand"
                />
              </template>
            </el-table-column>
            <el-table-column prop="checkNo" label="复核台类型"></el-table-column>
            <el-table-column prop="num" label="各岛类型分配阈值">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.num"
                  type="text"
                  placeholder="请输入各岛类型分配阈值"
                />
              </template>
            </el-table-column>
            <el-table-column prop="ceterTobNum" label="各岛中TOB分配阈值">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.ceterTobNum"
                  type="text"
                  placeholder="请输入各岛中TOB分配阈值"
                />
              </template>
            </el-table-column>
            <el-table-column label="操作" width="100">
              <template slot-scope="scope">
                <el-button
                  @click="handleClick(scope.row)"
                  type="text"
                  size="small"
                  >修改</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="tobItem">
          <div class="tobTitle">多穿中小TOB控制</div>
          <el-table
            :data="tableDataoff"
            border
            height="214"
            :header-cell-style="{ background: '#1890ff', color: '#ffffff' }"
          >
            <!-- <el-table-column prop="id" label="主键"></el-table-column> -->
            <el-table-column prop="paramDesc" label="描述">
            </el-table-column>
            <el-table-column prop="paramValue" label="参数开关">
              <template slot-scope="scope">
                <!-- <el-input
                  v-model="scope.row.paramValue"
                  type="text"
                  placeholder="请输入参数开关"
                /> -->
                <el-switch
                  v-model="scope.row.paramValue"
                  active-color="#13ce66"
                  inactive-color="#dedede"
                  active-value="1"
                  inactive-value="0"
                ></el-switch>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="100">
              <template slot-scope="scope">
                <el-button
                  @click="handleParamsoff(scope.row)"
                  type="text"
                  size="small"
                  >修改</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="tobItemtras">
          <!-- <div class="tobTitle">多穿阀值设置</div> -->
          <el-table
            :data="tableDataparam"
            border
            height="331"
            :show-header="false"
            :header-cell-style="{ background: '#1890ff', color: '#ffffff' }"
          >
            <!-- <el-table-column prop="id" label="主键"></el-table-column> -->
            <el-table-column prop="paramDesc" label="描述">
            </el-table-column>
            <el-table-column prop="paramValue" label="参数值">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.paramValue"
                  type="text"
                  placeholder="请输入参数开关"
                />
              </template>
            </el-table-column>
            <el-table-column label="操作" width="100">
              <template slot-scope="scope">
                <el-button
                  @click="handleParams(scope.row)"
                  type="text"
                  size="small"
                  >修改</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div class="tob">
        <div class="tobTitle">复核台阀值</div>
        <div class="tobTable">
          <el-table
            :data="tableDataCheckNo"
            border
            height="800"
            :header-cell-style="{ background: '#1890ff', color: '#ffffff' }"
          >
            <el-table-column prop="checkNo" label="复核台号"></el-table-column>
            <el-table-column prop="isLand" label="岛类型">
              <template slot-scope="scope">
                <dict-tag
                  :options="dict.type.island_type"
                  :value="scope.row.isLand"
                />
              </template>  
            </el-table-column>
            <el-table-column prop="num" label="复核台类型分配阈值">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.num"
                  type="text"
                  placeholder="请输入复核台类型分配阈值"
                />
              </template>
            </el-table-column>
            <el-table-column prop="ceterTobNum" label="中TOB分配阈值">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.ceterTobNum"
                  type="text"
                  placeholder="请输入中TOB分配阈值"
                />
              </template>
            </el-table-column>
            <el-table-column label="操作" width="150">
              <template slot-scope="scope">
                <el-button
                  @click="handleCheckNo(scope.row)"
                  type="text"
                  size="small"
                  >修改</el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <div class="footer">
      <el-dialog
        title="操作验证"
        :visible.sync="centerDialogVisible"
        width="22%"
        left
        :close-on-click-modal="false"
      >
        <el-form
          :model="passForm"
          status-icon
          :rules="passrules"
          ref="passForm"
          label-width="60px"
          class="demo-ruleForm"
        >
          <el-form-item label="密码" prop="pass">
            <el-input
              type="password"
              v-model="passForm.pass"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="centerDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="submit('passForm')"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import {
  getToList,
  getTobcheck,
  getSwitchList,
  getSwitchoffList,
} from "@/api/island";
import { updateChangenum, updateTobswitch } from "@/api/multiPass";
import { getcheckPassword } from "@/api/subSystem/continer";
export default {
  dicts: ["island_type"],
  data() {
    var passwordError = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("密码不能为空"));
      } else {
        getcheckPassword(value).then((res) => {
          if (res.msg == "admin") {
            callback();
          } else if (res.msg == "false") {
            callback(new Error("密码错误"));
          }
        });
      }
    };
    return {
      tableDataTob: [],
      tableDataCheckNo: [],
      tableDataparam: [],
      tableDataoff: [],
      centerDialogVisible: false,
      passForm: {
        pass: null,
      },
      areaNovalue: 0,
      passrules: {
        pass: [{ validator: passwordError, trigger: "blur" }],
      },
      //  岛密码修改
      tobisLand: null,
      tobNum: null,
      tobceterTobNum: null,
      // 复核台密码修改
      tobcheckNo: null,
      checkNum: null,
      checkceterTobNum: null,
      // 参数修改
      switchiD: null,
      switchnum: null,
    };
  },
  mounted() {
    this.tolist();
  },
  methods: {
    goBack() {
      this.$router.push("/subSystem1");
    },
    tolist() {
      getToList().then((res) => {
        console.log(res);
        this.tableDataTob = res.data;
      });
      getTobcheck().then((res) => {
        console.log(res);
        this.tableDataCheckNo = res.data;
      });
      getSwitchList().then((res) => {
        console.log(res);
        this.tableDataparam = res.data;
      });
      getSwitchoffList().then((res) => {
        this.tableDataoff = res.data;
      });
    },
    // 岛阀值设置
    handleClick(row) {
      this.centerDialogVisible = true;
      this.passForm.pass = null;
      this.areaNovalue = 1;
      this.tobisLand = row.isLand;
      this.tobNum = row.num;
      this.tobceterTobNum = row.ceterTobNum;
    },
    // 复核台阀值
    handleCheckNo(row) {
      this.centerDialogVisible = true;
      this.passForm.pass = null;
      this.areaNovalue = 2;
      this.tobcheckNo = row.checkNo;
      this.checkNum = row.num;
      this.checkceterTobNum = row.ceterTobNum;
    },
    // 多穿阀值设置
    handleParams(row) {
      this.centerDialogVisible = true;
      this.passForm.pass = null;
      this.areaNovalue = 3;
      this.switchiD = row.id;
      this.switchnum = row.paramValue;
    },
    // 中B/小B开关设置
    handleParamsoff(row) {
      this.centerDialogVisible = true;
      this.passForm.pass = null;
      this.areaNovalue = 4;
      this.switchiD = row.id;
      this.switchnum = row.paramValue;
    },
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.areaNovalue == 1) {
            // console.log(this.tobisLand,this.tobNum,this.tobceterTobNum);
            updateChangenum({
              isLand: this.tobisLand,
              num: this.tobNum,
              ceterTobNum: this.tobceterTobNum,
              checkNo: null,
            }).then((res) => {
              console.log(res);
              this.tolist();
            });
          } else if (this.areaNovalue == 2) {
            // console.log(this.checkNum,this.checkceterTobNum,this.tobceterTobNum,this.tobcheckNo);
            updateChangenum({
              isLand: null,
              num: this.checkNum,
              ceterTobNum: this.checkceterTobNum,
              checkNo: this.tobcheckNo,
            }).then((res) => {
              console.log(res);
              this.tolist();
            });
          } else if (this.areaNovalue == 3 || this.areaNovalue == 4) {
            // console.log(this.switchnum,this.switchiD);
            updateTobswitch({ num: this.switchnum, iD: this.switchiD }).then(
              (res) => {
                console.log(res);
                this.tolist();
              }
            );
          }
          this.centerDialogVisible = false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  .header {
    margin-top: -10px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .el-date-editor.el-input,
    .el-date-editor.el-input__inner {
      width: 220px;
      margin-right: 20px;
    }

    .backB {
      cursor: pointer;

      img {
        width: 20%;
      }
    }
  }
  .bigtitle {
    margin-bottom: 6px;
    margin-left: 43%;
  }
  ::v-deep .el-dialog:not(.is-fullscreen) {
    margin-top: 10vh !important;
  }

  .title {
    font-size: 16px;
    margin-bottom: 15px;
    color: #808080;
    width: 170px;
    padding: 5px;
    border-bottom: 1px dotted #8ddfff;
  }

  .el-icon-data-board::before {
    color: #00d9ff;
    margin-right: 8px;
  }
  .container {
    display: flex;
    justify-content: space-between;
    width: 100%;
    height: 1000px;
    // border: 1px solid #e4e4e479;
    padding: 10px;
  }
  .tob {
    width: 48%;
    height: 900px;
    border: 1px solid #e4e4e4e1;
  }
  //   .tobItem {
  //     height: 30%;
  //   }
  .tobItem{
    margin-top: 50px;
  }
  .tobItemtras{
    margin-top: -116px;
  }
  .tobTitle {
    text-align: center;
    width: 100%;
    height: 50px;
    line-height: 50px;
  }
  .tobTable {
    height: 800px;
    overflow: auto;
  }
}
</style>